Skip to main content

Canny Edge Detector

Identifies edges in an image by detecting areas of rapid intensity changes, highlighting object boundaries and edges with thin and accurate lines.

🖞ïļ Image options and parameters of cannyEdgeDetector method

The Canny edge detector is a popular and widely used image processing technique for detecting edges in images. It is widely used in computer vision, image processing, and various applications such as object recognition, image segmentation, and feature extraction due to its ability to accurately detect edges and suppress noise.

Applying Canny edge detector​

placeholderplaceholder
Ran in 0.00Ξs (Infinity ops/s)

The Canny edge detector is known for its ability to:

  • Detect edges with good localization (i.e., edges are thin and located precisely).
  • Suppress noise due to the Gaussian smoothing.
  • Handle edges with varying levels of intensity (gradient).
  • Allow for customization through the selection of appropriate threshold values.

Kinds of images compatible with algorithm​

Image propertyWhat it meansPossible values
bitDepthnumber of bits per channel[8,16]
componentsnumber of components[1]
alphais alpha channel allowedfalse

Parameters and default values​

  • options

Options​

PropertyRequiredDefault value
gaussianBlurOptionsno1
highThresholdno0.1
lowThresholdno0.04
hysteresisnotrue
outno-
Implementation

The Canny edge detector consists of several stages:

Smoothing: The first step involves applying a Gaussian filter to the input image. This helps reduce noise and smooth out small variations in pixel values.

Gradient Calculation: After smoothing, the gradient of the image is calculated using convolution with Sobel masks in both the horizontal and vertical directions. This step highlights regions of rapid intensity change in the image.

Non-maximum Suppression: In this step, the gradient magnitude is examined at each pixel location, and non-maximum values are suppressed. This means that only the local maxima in gradient magnitude are retained, which helps thinning the edges and keeping only the most prominent ones.

(optional)

Edge Tracking by Hysteresis : This step involves tracking edges by applying two thresholds: a high threshold and a low threshold. Pixels with gradient magnitude values above the high threshold are considered strong edges, while those between the low and high thresholds are considered potential edges. The algorithm then connects potential edges to strong edges, forming continuous edge contours.

Finally, edge tracking by hysteresis is performed to link weak edges to strong edges. This helps in forming continuous edges and eliminating isolated weak edges caused by noise.

The output of the Canny edge detector is a binary image(mask) where edges are represented as white lines.

info

The choice of threshold values for the high and low thresholds can affect the performance of the Canny edge detector and may need to be adjusted depending on the specific application and the characteristics of the input image.